package opertion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOpertion implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要归还的书名");
        String name=sc.nextLine();
        System.out.println("请输入你要归还书的作者");
        String author=sc.nextLine();
        System.out.println("请输入你要归还书的类型");
        String type=sc.nextLine();
        System.out.println("请输入你要归还书的价格");
        int price=sc.nextInt();
        Book book=new Book(name,author,type,price);
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if (bookList.getBooks()[i].equals(book)&&bookList.getBooks()[i].isBorrowed()==true){
                bookList.getBooks()[i].setBorrowed(false);
                System.out.println("归还成功");
                return;
            }else if(bookList.getBooks()[i].equals(book)&&bookList.getBooks()[i].isBorrowed()!=true){
                System.out.println("该书未被借出");
            }
        }
        System.out.println("没有该书");
    }
}
